#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>

void* thread_func(void* arg){
    int thread_id=*((int*)arg);
    printf("线程%d开始执行\n", thread_id);
    pthread_exit(NULL);
}

int main(){
    int num_threads=5;
    pthread_t threads[num_threads];
    int thread_ids[num_threads];
    int rc;
    int i;
    for(i=0;i<num_threads;i++){
        thread_ids[i]=i;
        rc=pthread_create(&threads[i], NULL, thread_func, (void*)&thread_ids[i]);
        if(rc){
            printf("ERROR; return code from pthread_create() is %d\n", rc);
            exit(-1);
        }
    }
    for(i=0;i<num_threads;i++){
        pthread_join(threads[i], NULL);
    }
    printf("所有线程执行完毕\n");
    pthread_exit(NULL);
}